{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app '__main__'\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.\n",
      " * Running on http://127.0.0.1:5000\n",
      "Press CTRL+C to quit\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask\n",
    "app = Flask(__name__)#实列化\n",
    "\n",
    "#string 接受任何不包含斜杠的文本\n",
    "#int  接受正整数\n",
    "#float 接受浮点数\n",
    "#path 接受包含斜杠的文本\n",
    "@app.route('/use/<int:id>')\n",
    "def index(id):\n",
    "    if id == 1:\n",
    "        return 'a'\n",
    "    if id == 2:\n",
    "        return 'b'\n",
    "    return 'hello weorld'\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app '__main__'\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.\n",
      " * Running on all addresses (0.0.0.0)\n",
      " * Running on http://127.0.0.1:5000\n",
      " * Running on http://192.168.31.11:5000\n",
      "Press CTRL+C to quit\n",
      "192.168.31.238 - - [25/Dec/2024 15:37:29] \"GET /user/1 HTTP/1.1\" 200 -\n",
      "192.168.31.238 - - [25/Dec/2024 15:37:34] \"GET /user/2 HTTP/1.1\" 200 -\n",
      "192.168.31.238 - - [25/Dec/2024 15:37:37] \"GET /user/2 HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask  \n",
    "\n",
    "app = Flask(__name__)  # 实例化  \n",
    "\n",
    "@app.route('/user/<int:id>')  # 定义路由  \n",
    "def index(id):  \n",
    "    if id == 1:  \n",
    "        return '丁喜龙是sb'  \n",
    "    if id == 2:  \n",
    "        return '瓦达西'  \n",
    "    return 'hello world'  \n",
    "\n",
    "if __name__ == '__main__':  \n",
    "    app.run(host='0.0.0.0')  # 让 Flask 对所有网络接口可见"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pytorchgpu",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
